﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using Model;

namespace Web.admin.InnerManage.AwardManage
{
    public partial class EditPercent : System.Web.UI.Page
    {
        BLL.PercentService percentservice = new BLL.PercentService();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request.QueryString["CON_ID"]))
                {
                    lb_Bind(Request.QueryString["CON_ID"]);
                    Rp_Bind(Request.QueryString["CON_ID"]);
                }
                else
                {
                    Response.Write("<script>alert('禁止修改地址')</script>");
                }
            }
        }

        /// <summary>
        ///根据竞赛绑定相应的label控件
        /// </summary>
        /// <param name="CON_ID"></param>
        protected void lb_Bind(string CON_ID)
        {
            BLL.ContestService contestservice = new BLL.ContestService();
            BoContests contestModel = contestservice.getContest(CON_ID);
            lb_ConName.Text = contestModel.CON_NAME;
        }

        /// <summary>
        /// 对repeater的绑定
        /// </summary>
        protected void Rp_Bind(string CON_ID)
        {
            string constr = "PER_CONTEST ='" + CON_ID + "'";
            rp_award.DataSource = percentservice.Getv_Participant(constr);
            rp_award.DataBind();
        }

        /// <summary>
        /// 保存修改确定事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void EditPersent(object sender, EventArgs e)
        {
            for (int i = 0; i < rp_award.Items.Count; i++)
            {
                string PercentId = ((HiddenField)rp_award.Items[i].FindControl("HF_id")).Value;
                TextBox tb = (TextBox)rp_award.Items[i].FindControl("tb_persent");
                TextBox tb_order = (TextBox)rp_award.Items[i].FindControl("tb_order");
                if (!string.IsNullOrEmpty(tb.Text.Trim()) && !string.IsNullOrEmpty(tb_order.Text.Trim()))
                {
                    BoPercent percentModel = percentservice.GetModelById(PercentId);
                    percentModel.PER_PERSENT = Convert.ToInt32(tb.Text);
                    percentModel.PER_ORDER = Convert.ToInt32(tb_order.Text);
                    percentservice.update(percentModel);
                }
            }
            Response.Write("<script>alert('修改成功')</script>");
        }
    }
}